package de.rj.urwalking.tasks;

import java.io.File;
import java.io.IOException;

import android.os.AsyncTask;
import android.os.Environment;
import android.util.Log;
import de.rj.urwalking.config.Config;

public class LoggerTask extends AsyncTask<String, String, Boolean> {

	private static final String TAG = Config.TAG;
	private static final boolean DEBUG = Config.DEBUG;

	@Override
	protected Boolean doInBackground(String... params) {

		if (DEBUG) Log.d(TAG, "starting logger");

		try {
			File path = new File(Environment.getExternalStorageDirectory(), Config.FOLDER_NAME);
			path.mkdirs();
			File fileName = new File(path, "logcat.txt");
			fileName.createNewFile();

			String cmd = "logcat -d -v time -f " + fileName.getAbsolutePath() + " AndroidRuntime URwalking *:S";
			Runtime.getRuntime().exec(cmd);
		} catch (IOException e) {
			Log.e(TAG, "error creating log file");
			e.printStackTrace();
			return false;
		}
		return true;
	}

}
